package com.snail.billing.json;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonCards extends JsonBase {

	private List<Card> cards;

	public JsonCards(String jsonString) {
		super(jsonString);
		try {
			if (getCode() == 1) {
				JSONObject json = new JSONObject(jsonString);
				JSONArray jsonArray = json.getJSONArray("cards");
				cards = new ArrayList<Card>();
				for (int i = 0; i < jsonArray.length(); i++) {
					Card card = new Card(jsonArray.getString(i));
					cards.add(card);
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public List<Card> getCards() {
		return cards;
	}

	public class Card {
		private int id;
		private String cardName;
		private BigDecimal price;
		private int money;
		private int point;
		private String currencyName;
		private String currency;
		private String platmentId;

		public Card(String jsonString) {
			try {
				JSONObject json = new JSONObject(jsonString);
				if (json.has("ID")) {
					id = json.getInt("ID");
				}
				if (json.has("CARD_NAME")) {
					cardName = json.getString("CARD_NAME");
				}
				if (json.has("PRICE")) {
					price = BigDecimal.valueOf(json.getDouble("PRICE"));
				}
				if (json.has("MONEY")) {
					money = json.getInt("MONEY");
				}
				if (json.has("POINT")) {
					point = json.getInt("POINT");
				}
				if (json.has("CURRENCY_NAME")) {
					currencyName = json.getString("CURRENCY_NAME");
				}
				if (json.has("CURRENCY")) {
					currency = json.getString("CURRENCY");
				}
				if (json.has("PLATMENT_ID")) {
					platmentId = json.getString("PLATMENT_ID");
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		public int getId() {
			return id;
		}

		public String getCardName() {
			return cardName;
		}

		public BigDecimal getPrice() {
			return price;
		}

		public int getMoney() {
			return money;
		}

		public int getPoint() {
			return point;
		}

		public String getCurrencyName() {
			return currencyName;
		}

		public String getCurrency() {
			return currency;
		}

		public String getPlatmentId() {
			return platmentId;
		}
	}
}
